/*
 * Created on 2005-10-8
 *
 */
package com.hd123.rumba.runtime;

import java.io.IOException;
import java.io.InputStream;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

/**
 * @author caili
 */
public class Properties {
  private static Properties instance = null;
  private static final java.util.Properties props = new java.util.Properties();

  private Properties() {
  }

  public static Properties getInstance() {
    if (instance == null) {
      instance = new Properties();
      initialize();
    }
    return instance;
  }

  /**
   * 从rumba.properties中读取接口的实现类
   */
  private static void initialize() {
    String fn = "/rumba.properties";
    Log log = LogFactory.getLog(NamingMgr.class);
    InputStream stream = Properties.class.getResourceAsStream(fn);
    if (stream == null) {
      log.info("没有找到文件" + fn + ".");
    } else {
      try {
        props.load(stream);
        log.info("从文件" + fn + "中读入:" + props);
      } catch (Exception e) {
        log.error("读取文件" + fn + "时发生错误.");
      } finally {
        try {
          stream.close();
        } catch (IOException ioe) {
          log.error("无法关闭文件" + fn, ioe);
        }
      }
    }

  }

  public String get(String key) {
    return (String)props.get(key);
  }
}
